package dict

import (
	"github.com/micro-plat/hydra"
	"github.com/micro-plat/lib4go/types"
)

// AddTypeValue 添加类型值
func AddValue(tenantID int, label, value string, pid int) error {
	db := hydra.C.DB().GetRegularDB()
	params := map[string]interface{}{
		"label":     label,
		"value":     value,
		"pid":       pid,
		"tenant_id": tenantID,
	}
	_, err := db.ExecuteBatch(sqlInsertDics, params)
	return err
}

// DeleteDict 删除数据
func DeleteDict(tenantID int, id int64) error {
	db := hydra.C.DB().GetRegularDB()
	params := map[string]interface{}{
		"id":        id,
		"tenant_id": tenantID,
	}
	_, err := db.Execute(sqlDeleteDic, params)
	return err
}

// sqlQueryAllDics 查询所有数据
func QueryAllDicts(tenantID int) (types.XMaps, error) {
	db := hydra.C.DB().GetRegularDB()
	params := map[string]interface{}{
		"tenant_id": tenantID,
	}
	data, err := db.Query(sqlQueryAllDics, params)
	return data, err
}
